From: Ian Jackson Date: Fri, 6 Dec 2013 16:40:08 +0000 (+0000) Subject: libxl: suspend: Fix suspend wait corner cases X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~5406 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=8ae14b99e00cd9a42ab4cd6538de987783f21de1;p=xen.git libxl: suspend: Fix suspend wait corner cases When we are waiting for a guest to suspend, this suspend operation would continue to wait (until the timeout) if the guest was destroyed or shut down for another reason, or if xc_domain_getinfolist failed. Handle these cases correctly, as errors. Signed-off-by: Ian Jackson CC: Stefano Stabellini Acked-by: Ian Campbell --- v3: Remove unwanted error call after a new "goto err". --- diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index 5d6dcc4ba0..28855a1101 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -1209,24 +1209,41 @@ static void suspend_common_wait_guest_watch(libxl__egc *egc, STATE_AO_GC(dss->ao); xc_domaininfo_t info; int ret; + int shutdown_reason; /* Convenience aliases */ const uint32_t domid = dss->domid; ret = xc_domain_getinfolist(CTX->xch, domid, 1, &info); - if (ret == 1 && info.domain == domid && - (info.flags & XEN_DOMINF_shutdown)) { - int shutdown_reason; - - shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) - & XEN_DOMINF_shutdownmask; - if (shutdown_reason == SHUTDOWN_suspend) { - LOG(DEBUG, "guest has suspended"); - domain_suspend_common_guest_suspended(egc, dss); - return; - } + if (ret < 0) { + LOGE(ERROR, "unable to check for status of guest %"PRId32"", domid); + goto err; + } + + if (!(ret == 1 && info.domain == domid)) { + LOGE(ERROR, "guest %"PRId32" we were suspending has been destroyed", + domid); + goto err; + } + + if (!(info.flags & XEN_DOMINF_shutdown)) + /* keep waiting */ + return; + + shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) + & XEN_DOMINF_shutdownmask; + if (shutdown_reason != SHUTDOWN_suspend) { + LOG(DEBUG, "guest %"PRId32" we were suspending has shut down" + " with unexpected reason code %d", domid, shutdown_reason); + goto err; } - /* otherwise, keep waiting */ + + LOG(DEBUG, "guest has suspended"); + domain_suspend_common_guest_suspended(egc, dss); + return; + + err: + domain_suspend_common_failed(egc, dss); } static void suspend_common_wait_guest_timeout(libxl__egc *egc,